<? require_once('con_db.php.inc'); ?>
<html>
<head>
<title>우편번호 검색</title>
</head>

<body>
<html>
<head>
<style>
body { margin: 0; font-size:12px; }
td { font-size:12px; }
a:link   { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:active  { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:visited  { font-family:"돋움"; text-decoration:none; color:#000000; line-height: 18px;}
a:hover  { font-family:"돋움"; text-decoration:underline;  color:#000000; line-height: 18px;}
</style>
<title>우편번호 검색</title>
</head>

<body onload="javascript:document.getElementById('s').focus();">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td valign="top" bgcolor="#eeeeee"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td style="letter-spacing:-1px; padding: 0 20px 17px 20px">검색을 원하시는 주소지를 동/읍/면 단위로 입력한 다음, <font color="#ED0063"><strong>검색 버튼</strong></font>을 누르세요.<br>
          (예 : 서초동 → 서초,  부안읍 → 부안,  수내면 → 수내 )</td>
      </tr>
      <tr>
        <td style="padding: 0 15px 0 20px;">
          <center><form action="thumb_postcode.php" method="post">
            <strong>읍/면/동</strong>
            <input id="s" name="s" type="text" size="30" value="<?=$s?>">
            <input type="submit" value="검색" align="absmiddle">
          </form>
          </center>
          <script type="text/javascript">
            <!--
            function copy(address) {
							document.addr.action="thumb_form.php"
							opener.thumb_form.address.value = address;
							opener.thumb_form.address2.readOnly = false;
							opener.thumb_form.address2.focus();
              window.close();
            }
            //-->
          </script>
            <?
				$s=$_POST['s'];

              if($s) {
                $query = "select * from postcode where (gugun like '%$s%') or (dong like '%$s%') ";
//    echo $query;
                $result = mysql_query($query, $db);
                while($data = mysql_fetch_array($result))  {
                  
                  $zipcode = $data[zipcode];
                  $sido = $data[sido];
                  $gugn = $data[gugun];
                  $dong		= $data[dong];
                  $bunji = $data[bungi];
                  
                  $tmp = explode("-",$zipcode);
                  $a = $tmp[0];
                  $b = $tmp[1];
            ?>
									<form name="addr" method="post">
												<a href="#" onclick="copy('<?=$sido?> <?=$gugn?> <?=$dong?> <?=$ri?>')">
												[<?=$a?>-<?=$b?>] <?=$sido?> <?=$gugn?> <?=$dong?> <?=$ri?> <?=$bunji?></a><br>
									</form>
            <?
                }
              }
              else {
                echo "검색하지 않았거나, 검색결과가 없습니다.";
              }
            ?>
        </td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>